var api = require('./api');
var apiNote = require('./apiNote');
var standardErrors = require('./standardErrors');

// Add api routes here 
var handle = {};
// API
handle['authenticate'] = api.authenticate;
handle['createAccount'] = api.createAccount;
// NOTE
handle['note/add'] = apiNote.add;
handle['note/show'] = apiNote.show;
handle['note/remove'] = apiNote.remove;

function route(req, res, controller) {

	console.log("controller : " + controller);
	if (controller != null) {
		if (handle[controller] != null) {
			handle[controller](req, res);
		} else {
			standardErrors.error404(res);
		}
	} else {
		standardErrors.error500(res);
	}
}

function apiRoute(req, res) {
	var calledController = req.params.api_controller;
	route(req, res, calledController);
}
exports.apiRoute = apiRoute;

function noteApiRoute(req, res) {
	var calledController = req.params.note_controller;
	if (calledController != null) {
		route(req, res, "note/" + calledController);
	}
}
exports.noteApiRoute = noteApiRoute;




